import { ref } from "vue";
import { defineStore } from 'pinia';

export const useUserStore = defineStore("user", () => {

  const jwt = ref("");
  const user = ref({
    authCode: null,
    exp: null,
    id: null,
    username: "",
  });

  const setJwt = (str) => {
    jwt.value = str;
  };
  const setUserData = (data) => {
    user.value = {...data};
  };
const clear=()=>{
  setJwt("")
  setUserData({
    authCode: null,
    exp: null,
    id: null,
    username: "",
  })
}

  return {
    setJwt,
    jwt,
    setUserData,
    user,
    clear
  };
}, {
  persist: {
    storage: {
      getItem(key) {
        return uni.getStorageSync(key);
      },
      setItem(key, value) {
        uni.setStorageSync(key, value);
      },
    },
  }
});
